package com.gsi.webstore.platform.storefront.capi.basket;

import com.gsi.webstore.platform.storefront.internal.basket.GSIBasketBOImpl;
import com.intershop.sellside.appbase.b2c.capi.basket.B2CBasketBO;
import com.intershop.sellside.appbase.b2c.capi.basket.B2CBasketBOContext;
import com.intershop.sellside.appbase.b2c.capi.basket.B2CBasketBOProxyFactory;

public class GSIBasketBOProxyFactory extends B2CBasketBOProxyFactory
{
    @Override
    public B2CBasketBO createBasket(B2CBasketBO basket, B2CBasketBOContext context)
    {
        // Note: the calculation result view proxy is already created in the basket repository 
        
        // needed for ProductConfigurationLineItemBOGSIExtension
        context.setVariable("CalculationResultView", basket.getCalculationResultView()); 
       return new GSIBasketBOImpl(basket, context, basket.getCalculationResultView());
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T extends com.intershop.beehive.core.capi.businessobject.BusinessObject, X extends com.intershop.beehive.core.capi.businessobject.BusinessObjectContext> T createBusinessObject(T businessObject, X context) {
        if (businessObject instanceof B2CBasketBO)
        {
            B2CBasketBO basketBO = (B2CBasketBO)businessObject;
            return (T)createBasket(basketBO, (B2CBasketBOContext)context);
        }
        return super.createBusinessObject(businessObject, context);
    }
}
